const bookTypeTable = require('../tables/booktype');
const modelObj = {
	//获取小说类型列表
	getBookTypeListModel(callback) {
		bookTypeTable.findAll({
			order: [
				['typesort', 'ASC']
			]
		}).then(data => {
			callback(data);
		});
	},
	//创建小说类型
	createBookTypeModel(params, callback) {
		bookTypeTable.create(params).then(data => {
			callback(JSON.parse(JSON.stringify(data)));
		});
	},
	//更新小说类型
	updateBookTypeModel(id, params, callback) {
		bookTypeTable.update(params, {
			where: {
				id: id
			}
		}).then(data => {
			callback(data[0]);
		});
	},
	//删除小说类型
	deleteBookTypeModel(id, callback) {
		bookTypeTable.destroy({
			where: {
				id: id
			}
		}).then(data => {
			callback(data);
		})
	},
	//更新小说类型排序
	updateBookTypeSortModel(arr, callback) {
		bookTypeTable.bulkCreate(arr, {
			updateOnDuplicate:['typesort']
		}).then((err, data) => {
			if(err){
				console.log(err)
			}
			callback(data);
		});
	}
}
module.exports = modelObj;